<div class="judul"><?php echo anchor($linkBack, $prevPage);?> <span class="breadcrumb"><?php echo "$titlePage";?></span></div>
<?php
  $flashdata = $this->session->flashdata('message');
  $messages = isset ($flashdata)?pesan($flashdata):"";
  echo "$messages";
?>
<script type="text/javascript">
    $(document).ready(function(){
        $('.detail').hide();
        $('#detail').click(function(){
            $('.detail').slideToggle(300);
        })
    })
</script>
<?php
  foreach ($hasilPemilihanAdikAsuh['master'] as $master);
?>
<div class="data-input">
    <fieldset>
        <legend>Hasil Pemilihan Adik Asuh</legend>
        <label>Periode</label><span style="font-size: 11px;padding-top: 7px;"><?php echo $master['periode']?></span>
        <label>Tanggal</label><span style="font-size: 11px;padding-top: 7px;"><?php echo datefmysql($master['tanggal'])?></span>
    </fieldset>
</div>
<div class="data-list">
    <fieldset>
        <legend>Perangkingan Adik Asuh</legend>
        <table class="tabel" width="70%">
            <tr>
                <th>No</th>
                <th>Calon Adik Asuh</th>
                <th>Sekolah</th>
                <th>Kelas</th>
                <th>Tahun Ajaran</th>
                <th>Nilai</th>
                <th>Aksi</th>
            </tr>
            <?php
                $no = 1;
                foreach ($hasilPemilihanAdikAsuh['detail'] as $detail){
            ?>
            <tr class="<?php echo ($no%2)?'even':'odd';?>">
                <td style="text-align:center;"><?php echo "$no";?></td>
                <td><?php echo $detail['calon_adik_asuh'];?></td>
                <td><?php echo $detail['sekolah'];?></td>
                <td><?php echo $detail['kelas'].' '.$detail['tingkat_pendidikan'];?></td>
                <td><?php echo $detail['tahun_ajaran'].' '.$detail['semester'];?></td>
                <td><?php echo $detail['nilai'];?></td>
                <td class="aksi">
                  <?php 
                    if($detail['status'] == 0){
                        echo anchor('pemilihan_adik_asuh/pilih_adik_asuh/'.$detail['id_calon_adik_asuh'].'/'.$master['periode'].'', 'terima', 'class=active');
                    }else{
                        echo 'sudah diterima';
                    }
                  ?>
                </td>
            </tr>
            <?php
               $no++; 
                }
            ?>
        </table>
    </fieldset>
</div>
<?php
  echo form_button('', 'Detail', 'id=detail');
?>
<div class="data-list detail">
        <fieldset>
            <legend><?php echo "$formTitle";?></legend>
            <fieldset>
                <legend>Matrik Keputusan</legend>
                <table class="tabel" width="60%">
                    <tr>
                        <th rowspan="2" style="width: 10%;vertical-align: middle">Alternatif</th>
                        <th colspan="<?php echo count($kriteria['id']);?>">Kriteria</th>
                    </tr>
                    <tr>
                        <?php
                          foreach ($kriteria as $kri){
                        ?>
                        <th><?php echo "C".$kri['id_kriteria'];?></th>
                        <?
                          }
                        ?>
                    </tr>
                    <?php
                    $no = 0;
                    foreach ($alternatif as $alt){
                    ?>
                    <tr class="<?php echo ($no%2)?'even':'odd';?>">
                        <td style="text-align: center;font-weight: bold"><?php echo "A$alt[id_calon_adik_asuh]";?></td>
                        <?php
                          $num = 0;
                          foreach ($kriteria as $kri){
                        ?>
                        <td><?php echo $matrikKeputusan[$no][$num];?></td>
                        <?
                          $num++;
                          }
                        ?>
                    </tr>
                    <?php
                    $no++;
                    }
                    $num = 0;
                    foreach ($kriteria as $kri){
                        $pembagi = 0;
                        $no = 0;
                        foreach ($alternatif as $alt){
                            $pembagi = $pembagi + pow($matrikKeputusan[$no][$num], 2);
                            $no++;
                        }
                        $xTernormalisasi[] = sqrt($pembagi);
                        $num++;
                    }
                    ?>
                </table>
            </fieldset>
            <fieldset>
                <legend>Rating Kinerja Tiap Alternatif</legend>
                <table class="tabel" width="60%">
                  <tr>    
                    <?php
                        $num = 1;
                        foreach ($bobot as $bob){
                    ?>
                      <th><?php echo "R$num";?></th>
                    <?php  
                        $num++;
                        }  
                    ?>
                  </tr>
                  <tr>
                      <?php
                        foreach ($xTernormalisasi as $r){
                      ?>
                      <td><?php echo "$r";?></td>
                      <?php
                        }
                      ?>
                  </tr>
                </table>    
            </fieldset>
            <fieldset>
                <legend>Matrik Ternormalisasi</legend>
                <table class="tabel" width="60%">
                    <tr>
                        <th rowspan="2" style="width: 10%;vertical-align: middle">Alternatif</th>
                        <th colspan="<?php echo count($kriteria);?>">Kriteria</th>
                    </tr>
                    <tr>
                        <?php
                          foreach ($kriteria as $kri){
                        ?>
                        <th><?php echo "C".$kri['id_kriteria'];?></th>
                        <?
                          }
                        ?>
                    </tr>
                    <?php
                    $no = 0;
                    foreach ($alternatif as $alt){
                    ?>
                    <tr class="<?php echo ($no%2)?'even':'odd';?>">
                        <td style="text-align: center;font-weight: bold"><?php echo "A$alt[id_calon_adik_asuh]";?></td>
                        <?php
                          $num = 0;
                          foreach ($kriteria as $kri){
                        ?>
                        <td><?php echo ($matrikKeputusan[$no][$num]/$xTernormalisasi[$num]);?></td>
                        <?
                          $num++;
                          }
                        ?>
                    </tr>
                    <?php
                    $no++;
                    }?>
               </table>    
         </fieldset> 
         <fieldset>
             <legend>Matrik Ternormalisasi Terbobot</legend>
             <table class="tabel" width="60%">
                <tr>
                    <th rowspan="2" style="width: 10%;vertical-align: middle">Alternatif</th>
                    <th colspan="<?php echo count($kriteria);?>">Kriteria</th>
                </tr>
                <tr>
                    <?php
                      foreach ($kriteria as $kri){
                    ?>
                    <th><?php echo "C".$kri[id_kriteria];?></th>
                    <?
                      }
                    ?>
                </tr>
                <?php
                $no = 0;
                foreach ($alternatif as $alt){
                ?>
                <tr class="<?php echo ($no%2)?'even':'odd';?>">
                    <td style="text-align: center;font-weight: bold"><?php echo "A$alt[id_calon_adik_asuh]";?></td>
                    <?php
                      $num = 0;
                      foreach ($kriteria as $kri){
                    ?>
                    <td><?php echo ($matrikKeputusan[$no][$num]/$xTernormalisasi[$num])*$bobot[$num]['nilai'];?></td>
                    <?
                      $terbobot[$num][$no] = ($matrikKeputusan[$no][$num]/$xTernormalisasi[$num])*$bobot[$num]['nilai'];
                      $num++;
                      }
                    ?>
                </tr>
                <?php
                $no++;
                }?>
           </table> 
         </fieldset>
        <fieldset>
            <legend>Solusi Ideal Positif & Negatif</legend>
            <table width="60%" style="border:none;">
              <tr>
                  <td width="50%">
                      <table class="tabel" width="100%">
                        <tr>
                            <th colspan="3">Solusi Ideal Positif</th>
                        </tr>
                        <?php 
                        $no = 0;
                        foreach ($kriteria as $kri){
                        ?>
                        <tr class="<?php echo ($no%2)?'even':'odd';?>">
                            <td><?php echo "y<sub>$kri[id_kriteria]</sub><sup>+</sup>";?></td>
                            <td><?php echo $kriteria[$no]['jenis'];?></td>
                            <td>
                                <?php
                                  if($kriteria[$no]['jenis'] == 'Cost'){
                                      echo min($terbobot[$no]);
                                      $positif[$no] = min($terbobot[$no]);
                                  }else{
                                      echo max($terbobot[$no]);
                                      $positif[$no] = max($terbobot[$no]);
                                  }
                                ?>
                            </td>
                        </tr>
                        <?
                        $no++;
                        }
                        ?>
                    </table>
                  </td>
                  <td>
                     <table class="tabel" width="100%">
                        <tr>
                            <th colspan="3">Solusi Ideal Negatif</th>
                        </tr>
                        <?php 
                        $no = 0;
                        foreach ($kriteria as $kri){
                        ?>
                        <tr class="<?php echo ($no%2)?'even':'odd';?>">
                            <td><?php echo "y<sub>$kri[id_kriteria]</sub><sup>-</sup>";?></td>
                            <td><?php echo $kriteria[$no]['jenis'];?></td>
                            <td>
                                <?php
                                  if($kriteria[$no]['jenis'] == 'Cost'){
                                      echo max($terbobot[$no]);
                                      $negatif[$no] = max($terbobot[$no]);
                                  }else{
                                      echo min($terbobot[$no]);
                                      $negatif[$no] = min($terbobot[$no]);
                                  }
                                ?>
                            </td>
                        </tr>
                        <?
                        $no++;
                        }
                        ?>
                    </table> 
                  </td>
              </tr>  
            </table>  
        </fieldset>  
        <fieldset>
            <legend>Jarak Nilai Terbobot Dengan Solusi Ideal Positif & Negatif</legend>
            <table width="60%" style="border:none;">
                <tr>
                    <td>
                       <?php
                        $no = 0;
                        foreach ($alternatif as $alt){
                           $num = 0; 
                           $dtemp = 0;
                           $temp = 0;
                           foreach ($terbobot as $kri){
                             $temp = pow(($kri[$no]-$positif[$num]),2);
                             $dtemp = $dtemp + $temp;
                             $num++;  
                           } 
                           $dpositif[$no] = sqrt($dtemp);
                           $no++; 
                        }
                       ?> 
                        <table class="tabel" width="100%">
                            <tr>
                                <th colspan="2">Jarak Nilai Terbobot Dengan Solusi Ideal Positif</th>
                            </tr>
                            <?php
                               $no = 1;
                               foreach ($dpositif as $dpos){
                            ?>
                            <tr class="<?php echo ($no%2)?'odd':'even';?>">
                                <td><?php echo "D<sub>$no</sub><sup>+</sup>";?></td>
                                <td><?php echo "$dpos";?></td>
                            </tr>
                            <?php
                               $no++;
                               }
                            ?>
                        </table> 
                    </td>
                    <td>
                       <?php
                        $no = 0;
                        foreach ($alternatif as $alt){
                           $num = 0; 
                           $dtemp = 0;
                           $temp = 0;
                           foreach ($terbobot as $kri){
                             $temp = pow(($kri[$no]-$negatif[$num]),2);
                             $dtemp = $dtemp + $temp;
                             $num++;  
                           } 
                           $dnegatif[$no] = sqrt($dtemp);
                           $no++; 
                        }
                       ?> 
                       <table class="tabel" width="100%">
                            <tr>
                                <th colspan="2">Jarak Nilai Terbobot Dengan Solusi Ideal Negatif</th>
                            </tr>
                            <?php
                               $no = 1;
                               foreach ($dnegatif as $dneg){
                            ?>
                            <tr class="<?php echo ($no%2)?'odd':'even';?>">
                                <td><?php echo "D<sub>$no</sub><sup>-</sup>";?></td>
                                <td><?php echo "$dneg";?></td>
                            </tr>
                            <?php
                               $no++;
                               }
                            ?>
                       </table> 
                    </td>
                </tr>
            </table>
        </fieldset>   
        <fieldset>
            <legend>
                Kedekatan Setiap Alternatif Dengan Solusi Ideal
            </legend>
            <?php
                $no = 0;
                foreach ($dpositif as $dpos){
                   $v[$no] = $dnegatif[$no]/($dpos+$dnegatif[$no]);
                   $no++;
                }
            ?>
            <table class="tabel">
                <tr>
                    <th colspan="3">Kedekatan Setiap Alternatif Dengan Solusi Ideal</th>
                </tr>
                <?php
                    $no = 0;
                    foreach ($alternatif as $alt){
                ?>
                <tr class="<?php echo ($no%2)?'even':'odd';?>">
                    <td style="font-weight: bold;"><?php echo "A$alt[id_calon_adik_asuh]";?></td>
                    <td><?php echo $alt['calon_adik_asuh'];?></td>
                    <td><?php echo $v[$no];?></td>
                </tr>
                <?php
                      $no++;  
                    }
                ?>
            </table>
        </fieldset>    
        </fieldset>
</div> 